package pl.register.android.util.content;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import java.io.Serializable;

/**
 * @author Mateusz Strzelecki
 * @since 2013-04-09
 */

public class IntentBuilder {

    private Intent intent;

    private Bundle bundle;

    public static IntentBuilder intent(Activity from, Class to) {
        return new IntentBuilder(from, to);
    }

    private IntentBuilder(Activity from, Class to) {
        bundle = new Bundle();
        intent = new Intent(from, to);
    }

    public IntentBuilder withSerializable(String key, Serializable object) {
        bundle.putSerializable(key, object);
        return this;
    }

    public IntentBuilder withInt(String key, Integer integer) {
        bundle.putInt(key, integer);
        return this;
    }

    public Intent build() {
        if (!bundle.isEmpty()) {
            intent.putExtras(bundle);
        }
        return intent;
    }
}
